import { _decorator, Component, Node, systemEvent, SystemEvent, EventKeyboard, KeyCode, EventTouch, Touch } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('KeyboardEvent')
export class KeyboardEvent extends Component {
    onEnable() {
        // 键盘事件
        systemEvent.on(SystemEvent.EventType.KEY_DOWN, this._keyDown, this);

        // 触摸事件
        systemEvent.on(SystemEvent.EventType.TOUCH_START, this._touchStart, this);
        systemEvent.on(SystemEvent.EventType.TOUCH_END, this._touchEnd, this);
        systemEvent.on(SystemEvent.EventType.TOUCH_MOVE, this._touchMove, this);
    }

    start() {}

    _keyDown(event: EventKeyboard) {
        console.log(event);
        // console.log(event.keyCode);
    }

    /**
     * 触摸事件 -> 开始
     */
    _touchStart(touch: Touch, event: EventTouch) {
        // console.log('touch__Start:\t', event);
        console.log('touch__Start:\t', touch);
    }

    /**
     * 触摸事件 -> 结束
     */
    _touchEnd(touch: Touch, event: EventTouch) {
        // console.log('touch__End:\t', event);
        console.log('touch__End:\t', touch);
    }

    /**
     * 触摸事件 -> 移动中
     */
    _touchMove(touch: Touch, event: EventTouch) {
        // console.log('touch__Move:\t', event);
        // console.log('touch__Move:\t', touch);
    }

    onDisable() {}
}
